package com.hpin.mlxteacher.my;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hpin.mlxteacher.R;
import com.hpin.mlxteacher.base.BaseActivity;
import com.hpin.mlxteacher.widget.ActionSheetDialog;
import com.hpin.mlxteacher.widget.CircleImageView;

/**
 * 个人设置页面
 * Created by Aaron on 15/7/30.
 */
public class SettingActivity extends BaseActivity {

    //修改姓名
    private static final int CHANGE_NAME_CODE = 10021;
    //更改性别
    private static final int CHANGE_SEX_CODE = 10022;
    //更改学校,班级
    private static final int CHANGE_SCHOOL_CODE = 10023;
    //更改密码
    private static final int CHANGE_PSW_CODE = 10024;

    private CircleImageView cv_headpic;
    private TextView tv_name;
    private TextView tv_sex;
    private TextView tv_birthday;
    private TextView tv_tel;
    private TextView tv_school_grade;
    private Intent mIntent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_setting);

        initWidget();
    }

    private void initWidget() {

        ImageView tv_left = (ImageView) findViewById(R.id.iv_left);
        TextView tv_title = (TextView) findViewById(R.id.tv_title);

        tv_title.setText(getResources().getString(R.string.personal_setting));

        tv_left.setOnClickListener(this);

        RelativeLayout rl_head_pic = (RelativeLayout) findViewById(R.id.rl_head_pic);
        RelativeLayout rl_name = (RelativeLayout) findViewById(R.id.rl_name);
        RelativeLayout rl_sex = (RelativeLayout) findViewById(R.id.rl_sex);
        RelativeLayout rl_school_grade = (RelativeLayout) findViewById(R.id.rl_school_grade);
        RelativeLayout rl_change_psw = (RelativeLayout) findViewById(R.id.rl_change_psw);

        cv_headpic = (CircleImageView) findViewById(R.id.cv_headpic);
        tv_name = (TextView) findViewById(R.id.tv_name);
        tv_sex = (TextView) findViewById(R.id.tv_sex);
        tv_birthday = (TextView) findViewById(R.id.tv_birthday);
        tv_tel = (TextView) findViewById(R.id.tv_tel);
        tv_school_grade = (TextView) findViewById(R.id.tv_school_grade);

        rl_head_pic.setOnClickListener(this);
        rl_name.setOnClickListener(this);
        rl_sex.setOnClickListener(this);
        rl_school_grade.setOnClickListener(this);
        rl_change_psw.setOnClickListener(this);

    }

    @Override
    public void widgetClick(View v) {

        switch (v.getId()) {
            case R.id.iv_left:
                finish();
                break;
            case R.id.rl_head_pic://更换头像
                showChoose();
                break;
            case R.id.rl_name://更改姓名

                mIntent = new Intent(this, ChangeNameActivity.class);
                startActivityForResult(mIntent, CHANGE_NAME_CODE);

                break;
            case R.id.rl_sex://更改性别

                mIntent = new Intent(this, ChangeSexActivity.class);
                startActivityForResult(mIntent, CHANGE_SEX_CODE);

                break;
            case R.id.rl_school_grade://更改学校班级

                mIntent = new Intent(this, ChangeSchoolActivity.class);
                startActivityForResult(mIntent, CHANGE_SCHOOL_CODE);

                break;
            case R.id.rl_change_psw://更改密码
                mIntent = new Intent(this, ChangePswActivity.class);
                startActivityForResult(mIntent, CHANGE_PSW_CODE);
                break;

        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (data == null)
            return;

        switch (requestCode) {

            case CHANGE_NAME_CODE://修改姓名
                break;

        }

    }

    /**
     * 弹出选择照片的对话框
     */
    protected void showChoose() {

        new ActionSheetDialog(this)
                .builder()
                .setCancelable(true)
                .setCanceledOnTouchOutside(true)
                .addSheetItem("拍照", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                // 拍照
//                                getTakePhoto();

                            }

                        })
                .addSheetItem("去相册选择", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                // 从相册中选择
//                                getFromPhotoAlbum();
                            }
                        }).show();

    }

}
